/* 
 * Author: Marco Egli
 */

YUI().use('node', function(Y) {
    Y.one('#buttonSearchSites').on('click', function(e) {
        searchSites();
    });
    Y.one('#inputSearchSites').on('keydown',function(e) {
        if(e.charCode === 13){
            searchSites(); 
        }
    });
    
    var searchSites = function(){
        var sQuery = Y.one('#inputSearchSites').get('value');
        var sUrl = "https://www.google.ch/search?q="+sQuery;

        Y.all('#sectionGemeinden .domain').each(function (domainNode) {
            var domainName = domainNode.get('innerHTML');
            if(domainName.length > 0){
                sUrl += "+site%3A"+domainNode.get('innerHTML')+"+OR";
            }
        });
        sUrl += "+site%3Awww.familienvereine-bezirk-hinwil.ch&hl=de";
        
        Y.log(sUrl);
        var windowObjectReference = window.open(sUrl,"searchsites");
    }
    
    Y.use('gallery-scroll-nav', function(Y) {
         Y.one('body').plug(Y.Plugin.ScrollNav);
    });    
});

